package com.itheima;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

public class Demo6 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("qweqasd");
        list.add("aweqadasd");
        list.add("yweqasd");
        list.add("zqqqweqasd");
        list.add("sdjksdv");
        list.add("pjgj");
        list.add("sdaffhgfqwewq");
        list.add("acb");
        list.add("kmas");

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int num1 = o2.length() - o1.length();
                int num2 = num1 == 0 ? o1.compareTo(o2) : num1;
                return num2 == 0 ? 1 : num2;
            }
        });


        for (String s : list) {
            System.out.println(s);

        }
    }
}
